using System;
using System.Collections.Generic;
using UnityEngine;

public class TableTennisMainNavigation : NavigationManager
{
	public enum HeaderType
	{
		CoinsCashEnergy = 0,
		Diamonds = 1,
		None = 2
	}

	[Serializable]
	public class TrainingView
	{
		[Serializable]
		public class SkillTabButton
		{
			public PlayerStatsManager.SkillType skillType;

			public UITabButton button;
		}

		[Serializable]
		public class AttributeTabButton
		{
			public PlayerStatsManager.AttributeType attributeType;

			public UITabButton button;
		}

		public GameObject trainingLayer;

		public UITabController tabController;

		public List<SkillTabButton> skillButtons = new List<SkillTabButton>();

		public List<AttributeTabButton> attrButtons = new List<AttributeTabButton>();
	}

	[Serializable]
	public class ShopView
	{
		[Serializable]
		public class ShopTabButton
		{
			public StoreItemsConfig.StoreItem.ItemType itemType;

			public UITabButton button;
		}

		public GameObject itemShop;

		public UITabController tabController;

		public List<ShopTabButton> shopButtons = new List<ShopTabButton>();
	}

	[Serializable]
	public class CurrencyControl
	{
		public CurrencyType currency;

		public TableTennisCoinController control;
	}

	public CurrencyPurchaseLayer currencyPurchaseLayer;

	public StartupPanelController startupLayer;

	public TrainingTutorialManager trainingTutorial;

	public MultiplayerTrainingSelectLayer multiplayerSelectLayer;

	public MultiplayerLobbyLayer lobbyLayer;

	public GameObject winningsCaller;

	public PurchaseLayer purchaseLayer;

	public PlayerSkillTrainLayer skillsTrainLayer;

	public PlayerSkillsScreen specialSkillsScreen;

	public SkillMatchLoading skillMatchLoading;

	public ChallengeFailDialog challengeFailDialog;

	public EnergyControl energyControl;

	public List<CurrencyControl> currencyControls = new List<CurrencyControl>();

	public TrainingView trainingView;

	public TrainingAspectLayer trainingAspectLayer;

	public ShopView shopView;

	public EquipmentShopLayer equipmentShop;

	public GameObject nameAndFlagSelect;

	public CharacterDisplayView characterView;

	public FriendsDisplay facebookFriendPicker;

	public MyTeamLayer myTeamLayer;

	public CustomisationSelectLayer customisation;

	public GameScreen gameScreen;

	public HeaderControl header;

	public GameObject headerDiamonds;

	public GameObject careerLayer;

	public TableTennisGameStartScript gameStartScript;

	public IntroScreen introScreen;

	public TrainingCompleteDialog trainingCompleteDialog;

	public TableTennisRateCaller rateCaller;

	protected float desiredSoundVolume = 0.1f;

	public float soundVolumeLoud = 0.1f;

	public float soundVolumeInGame = 0.05f;

	public float soundVolumeSpeed = 2f;

	public List<GameObject> pathFromStartLayerToMultiplayerRoomSelect = new List<GameObject>();

	public List<GameObject> pathToCareerLayer = new List<GameObject>();

	public new static TableTennisMainNavigation instance
	{
		get
		{
			return NavigationManager.instance as TableTennisMainNavigation;
		}
	}

	public AudioListener audioListener
	{
		get
		{
			return GetComponent<AudioListener>();
		}
	}

	public AudioSource audioSource
	{
		get
		{
			return GetComponent<AudioSource>();
		}
	}

	public TableTennisCoinController GetCoinControlForCurrency(CurrencyType type)
	{
		foreach (CurrencyControl currencyControl in currencyControls)
		{
			if (currencyControl.currency == type)
			{
				return currencyControl.control;
			}
		}
		return null;
	}

	public void OnGameShown(bool gameShown)
	{
		if (gameShown)
		{
			audioListener.enabled = false;
			desiredSoundVolume = soundVolumeInGame;
		}
		else
		{
			audioListener.enabled = true;
			desiredSoundVolume = soundVolumeLoud;
		}
	}

	public void SetHeader(HeaderType type)
	{
		UITools.SetActive(header, type == HeaderType.CoinsCashEnergy);
		UITools.SetActive(headerDiamonds, type == HeaderType.Diamonds);
	}

	public HeaderType GetActiveHeaderType()
	{
		if (header.gameObject.activeSelf)
		{
			return HeaderType.CoinsCashEnergy;
		}
		if (headerDiamonds.gameObject.activeSelf)
		{
			return HeaderType.Diamonds;
		}
		return HeaderType.None;
	}

	protected override void Init()
	{
		base.Init();
		Notifications notifications = BehaviourSingletonInit<Notifications>.instance;
		notifications.ClearNotifications();
		audioSource.volume = soundVolumeLoud;
		desiredSoundVolume = soundVolumeLoud;
		if (SingletonInit<PlayerCareer>.Instance.maxStageReached >= 3)
		{
			Ads.instance.CreateInterstitial();
			Ads.instance.ShowInterstitial();
		}
		InAppPurchase inAppPurchase = InAppPurchase.instance;
		inAppPurchase.QueryInventory();
		BehaviourSingletonInit<SnapshotSyncManager>.instance.canSync = true;
	}

	public void PushCurrencyStore(CurrencyType type = CurrencyType.coins, Action<bool> onComplete = null)
	{
		currencyPurchaseLayer.Show(type, onComplete);
	}

	public override void Update()
	{
		if (!audioSource.enabled)
		{
			BehaviourSingleton<SoundManager>.instance.SetMusicVolume(GGPlayerSettings.instance.Model.musicVolume);
			BehaviourSingleton<SoundManager>.instance.SetSfxVolume(GGPlayerSettings.instance.Model.sfxVolume);
			audioSource.enabled = true;
		}
		audioSource.volume = Mathf.Lerp(audioSource.volume, desiredSoundVolume, RealTime.deltaTime);
		base.Update();
	}

	public void PushItemShop(StoreItemsConfig.StoreItem.ItemType activeType)
	{
		UITabButton uITabButton = null;
		foreach (ShopView.ShopTabButton shopButton in shopView.shopButtons)
		{
			if (shopButton.itemType == activeType)
			{
				uITabButton = shopButton.button;
				break;
			}
		}
		if (uITabButton != null)
		{
			shopView.tabController.activeTab = uITabButton;
		}
		Push(shopView.itemShop);
	}

	public void ShowFriendPicker(FriendsDisplay.FriendDisplayAction action, GGMessageConfig.FbObjectType giftType)
	{
		facebookFriendPicker.Init(action, giftType);
		PushModal(facebookFriendPicker.gameObject);
	}

	public void PushTraining(PlayerStatsManager.AttributeType type)
	{
		Push(trainingView.trainingLayer);
	}

	public void PushTraining(PlayerStatsManager.SkillType type)
	{
		switch (type)
		{
		case PlayerStatsManager.SkillType.Speed:
			equipmentShop.Show(StoreItemsConfig.StoreItem.ItemType.Shoe);
			break;
		case PlayerStatsManager.SkillType.Racket:
			equipmentShop.Show(StoreItemsConfig.StoreItem.ItemType.Racket);
			break;
		default:
			trainingAspectLayer.Show(type);
			break;
		}
	}

	public void PushNameAndFlagMenu()
	{
		NameAndCountrySelectController component = nameAndFlagSelect.GetComponent<NameAndCountrySelectController>();
		if (component.fullScreen)
		{
			Push(nameAndFlagSelect);
		}
		else
		{
			PushModal(nameAndFlagSelect);
		}
	}

	protected override void OnLoadingOver()
	{
		BehaviourSingleton<Social>.instance.signIn();
		Debug.Log("On loading over");
		BehaviourSingletonInit<FriendProfilesManager>.instance.RefreshFriendProfiles();
		GGPlayerSettings gGPlayerSettings = GGPlayerSettings.instance;
		base.loadingOver = true;
		Debug.Log(MenuParameters.InitParameters.showTrainingTutorial);
		List<GameObject> list = new List<GameObject>();
		list.Add(startLayer.gameObject);
		if (MenuParameters.InitParameters.multiplayerPush && !MenuParameters.InitParameters.showTrainingTutorial)
		{
			list.AddRange(pathFromStartLayerToMultiplayerRoomSelect);
			MenuParameters.InitParameters = new MenuParameters.MenuParams();
		}
		else if (MenuParameters.InitParameters.showCareer && !MenuParameters.InitParameters.showTrainingTutorial)
		{
			list.AddRange(pathToCareerLayer);
			MenuParameters.InitParameters = new MenuParameters.MenuParams();
		}
			list.Add(introScreen.gameObject);
			PushLayers(list, true);
		if (MenuParameters.InitParameters.showTrainingTutorial)
		{
			trainingTutorial.gameObject.SetActive(true);
			PushLayers(list, true);
		}
		else if (ConfigBase.instance.cloudSyncType == ConfigBase.GGFileIOCloudSyncTypes.GGSnapshotCloudSync)
		{
			PushLayers(list, false);
			if (!BehaviourSingletonInit<SnapshotSyncManager>.instance.syncInProgress)
			{
				BehaviourSingletonInit<SnapshotSyncManager>.instance.DoInitialSync(true);
			}
		}
		else
		{
			PushLayers(list, true);
		}
	}
	private new void PushLayers(List<GameObject> layers, bool shouldEnableLast)
	{
		for (int i = 0; i < layers.Count; i++)
		{
			bool activate = shouldEnableLast && i == layers.Count - 1;
			Push(layers[i], activate);
		}
		base.loadingOver = true;
	}
	public void GotoHomePage()
    {
		List<GameObject> list = new List<GameObject>();
		list.Add(introScreen.gameObject);
		PushLayers(list, true);
    }
}
